package com.lengxf.design.dynamic;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;

public class Client {

    public static void main(String[] args) {
        AbstractUserDAO abstractUserDAO = new UserDAO();
        InvocationHandler invocationHandler = new DAOLogHandler(abstractUserDAO);
        AbstractUserDAO proxy = (AbstractUserDAO) Proxy.newProxyInstance(AbstractUserDAO.class.getClassLoader(), new Class[]{AbstractUserDAO.class}, invocationHandler);
        proxy.findUserById("张无忌");
        System.out.println("---------------");
        AbstractDocumentDAO documentDAO = new DocumentDAO();
        InvocationHandler daoLogHandler = new DAOLogHandler(documentDAO);
        AbstractDocumentDAO proxy_new = (AbstractDocumentDAO) Proxy.newProxyInstance(AbstractDocumentDAO.class.getClassLoader(), new Class[]{AbstractDocumentDAO.class}, daoLogHandler);
        proxy_new.deleteDocumentById("D002");
    }

}
